/**
@file
	Utility.cpp
@brief

@author
	GengYong
@revision
	2005/11/05 * Created by GengYong.
*/

#include "StdUtility.h"

#if defined(LINUX)

unsigned long Util::CPU_FREQUENCY_KHZ = 0;

static struct CPU_Frequency_Resolver
{
	CPU_Frequency_Resolver()
	{
		FILE * fp = popen( "/bin/egrep -i '^cpu[ ]+MHz[^:]+:[ ]*[0-9.]+' /proc/cpuinfo |/bin/sed -e 's%[^:]*:[ ]*%%'", "r" );		
		if (fp != NULL)
		{
			char buf[32];
			fgets( buf, sizeof(buf), fp );
			pclose( fp );
			Util::CPU_FREQUENCY_KHZ = (unsigned long long)(strtol(buf, NULL, 10)*1000);
		}
		else
		{
			Util::CPU_FREQUENCY_KHZ = 1;
		}
	}	
} cpu_frequency__resolver;

#endif


